#include "liststack.h"

l*liststackcreat(void)//创建链式栈
{
    l *h = (l*)malloc(sizeof(l));
    if ( h == NULL)
    {
        printf("h创建失败!\n");
        return NULL;
    }

    h->data = 0;
    h->next = NULL;

    return h;
}

int isempty(l*h)//判空
{
    return h->next == NULL ? 0:-1;
}
void stackshow(l*h)//遍历
{
    while(h->next!=NULL)
    {
        h=h->next;
        printf("-%d",h->data);      
    }
    putchar(10);


}
int push(l*h,datatype data)//入栈
{
    l*temp;
    temp = (l*)malloc(sizeof(l));
    if( isempty(h) == 0)
    {
        printf("push 0\n");
        return -1;
    }
    temp->data = data;
    temp->next= h->next;
    h->next = temp;   
    return 0;
}

datatype pop(l*h)//出栈
{
    if( isempty(h)==0)
    {
        printf(" -1\n");
        return (datatype) -1;
    }
    l*temp = h->next;
    h->next = temp->next;

    datatype ldata = temp->data;

    if(temp!=NULL)
    {
        free(temp);
        temp = NULL;
    }
    return ldata;
}